/*
 * This source code is part of TWaver 4.0
 *
 * Serva Software PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * Copyright 2002 - 2011 Serva Software. All rights reserved.
 */

package demo.alarm.overview;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import twaver.Alarm;
import twaver.swing.LabelValueLayout;
 
public class AlarmUITextPane extends JPanel {
    LabelValueLayout layout = new LabelValueLayout();
    JLabel lbSpecificProblem = new JLabel();
    JTextField txtProbableCause = new JTextField();
    JTextField txtSpecificProblem = new JTextField();
    JLabel lbAdditionalText = new JLabel();
    JLabel lbProposedRepairAction = new JLabel();
    JTextField txtProposedRepairAction = new JTextField();
    JLabel lbProbableCause = new JLabel();
    JTextField txtAdditionalText = new JTextField();

    public AlarmUITextPane() {
        try {
            jbInit();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    void jbInit() throws Exception {
        lbSpecificProblem.setText("Specific problem:");
        this.setLayout(layout);
        lbAdditionalText.setText("Additional text:");
        lbProposedRepairAction.setText("Proposed repair action:");
        lbProbableCause.setText("Probable cause:");
        txtSpecificProblem.setEditable(false);
        txtSpecificProblem.setText("");
        txtProbableCause.setEditable(false);
        txtProbableCause.setText("");
        txtProposedRepairAction.setEditable(false);
        txtProposedRepairAction.setText("");
        txtAdditionalText.setEditable(false);
        this.add(lbProbableCause, null);
        this.add(txtProbableCause, null);
        this.add(lbProposedRepairAction, null);
        this.add(txtProposedRepairAction, null);
        this.add(lbSpecificProblem, null);
        this.add(txtSpecificProblem, null);
        this.add(lbAdditionalText, null);
        this.add(txtAdditionalText, null);
    }

    public void setAlarm(Alarm alarm) {
        reset();
        this.txtAdditionalText.setText(alarm.getAdditionalText());
        this.txtSpecificProblem.setText(alarm.getSpecificProblem());
        this.txtProbableCause.setText(alarm.getProbableCause() == null ? "" : alarm.getProbableCause().getName());
        this.txtProposedRepairAction.setText(alarm.getProposedRepairAction());
    }

    private void reset() {
        this.txtAdditionalText.setText("");
        this.txtProbableCause.setText("");
        this.txtProposedRepairAction.setText("");
        this.txtSpecificProblem.setText("");
    }
}